package xin.marcher.module.replenished.api.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import xin.marcher.framework.common.util.json.JsonUtils;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.exception.ProductBizException;
import xin.marcher.module.replenished.api.RecoverableApi;
import xin.marcher.module.replenished.domain.request.RecoverableRequest;
import xin.marcher.module.replenished.service.RecoverableService;

import javax.annotation.Resource;

/**
 * 商品可采实现
 */

@Slf4j
@DubboService(version = "1.0.0", interfaceClass = RecoverableApi.class, retries = 0)
public class RecoverableApiImpl implements RecoverableApi {

    @Resource
    private RecoverableService recoverableService;

    @Override
    public JsonResult syncRecoverableProduct(RecoverableRequest request) {
        try {
            return recoverableService.syncRecoverableProduct(request);
        } catch (ProductBizException e) {
            log.error("biz error: request={}", JsonUtils.toJsonString(request), e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch (Exception e) {
            log.error("system error: request={}", JsonUtils.toJsonString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
